<template>
  <div class="meat">
    <!-- 一级菜单下面所拥有的二级菜单 -->
    <el-aside class="aside" :width="isCollapse ? '50px' : '200px'">
      <i
        class="el-icon-s-fold toggle-button"
        @click="toggleCollapse"
        v-if="isCollapse == false"
      ></i>
      <i
        class="el-icon-s-unfold toggle-button"
        @click="toggleCollapse"
        v-else
      ></i>
      <el-menu
        ref="menu"
        :default-active="activePath"
        router
        unique-opened
        :collapse-transition="false"
        :collapse="isCollapse"
        class="sidebar el-menu-vertical-demo"
        @select="openMenu"
        text-color="#A9B0B7"
        active-text-color="#0064F1"
      >
        <menu-tree :menuData="treeData"></menu-tree>
        <!-- <SideMenu :itemList='materialQualityManage'></SideMenu> -->
      </el-menu>
    </el-aside>
    <!-- 以及二级菜单所对应的页面 -->
    <el-main class="main_container">
      <router-view></router-view>
    </el-main>
  </div>
</template>

<script>
import menuTree from "@/components/commonPublic/menu.vue";
import { getBaseModuleList } from "@/api/request.js";
export default {
  components: {
    // SideMenu
    menuTree,
  },
  data() {
    return {
      // activePath: "entryLedger",
      activePath: "",

      isCollapse: false,
      // 场站生产
      treeData: [
        // 砼拌合生产质量管控
        {
          title: "砼拌合生产质量管控",
          img: "iconfont icon-xitongguanli1",
          name: "HntManage",
          left: 0,
          children: [
            {
              title: "理论配合比",
              path: "theoreticalMix",
              path2: "theoreticalMixText",
              name: "theoreticalMix",
              name2: "theoreticalMixText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "施工配合比",
              path: "proportionMix",
              path2: "proportionMixText",
              name: "proportionMix",
              name2: "proportionMixText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "浇筑令在线下发",
              path: "pouringOrder",
              path2: "pouringOrderText",
              name: "pouringOrder",
              name2: "pouringOrderText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "砼拌合生产配合比",
              path: "HntMixProportion",
              path2: "HntMixProportionText",
              name: "HntMixProportion",
              name2: "HntMixProportionText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "砼拌合生产数据信息",
              path: "supervisionList",
              path2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              name: "supervisionList",
              left: 37,
            },
            {
              title: "拌合生产超标监控",
              path2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              path: "closure",
              name: "closure",
              left: 37,
            },
               {
              title: "拌合设备检定管理",
              path: "EquipmentCalibration",
              path2: "EquipmentCalibrationText",
              name: "EquipmentCalibration",
              name2: "EquipmentCalibrationText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },

            {
              title: "拌合材料生产统计",
              name: "bhManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "阶段生产材料用量",
                  path: "Consumption",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "Consumption",
                  left: 37,
                },
                {
                  title: "拌合材料用量统计",
                  // title: '材料用量',
                  path: "deliverability",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "deliverability",
                  left: 37,
                },

                {
                  title: "用料偏差趋势分析",
                  path: "deviationTrend",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "deviationTrend",
                  left: 37,
                },

                {
                  title: "单日生产材料用量",
                  path: "timePeriod",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "timePeriod",
                  left: 37,
                },
              ],
            },
            {
              title: "拌合生产方量统计",
              name: "stManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "阶段生产方量统计",
                  path: "output",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "output",
                  left: 60,
                },
                {
                  title: "生产超标情况统计",
                  path: "exceedance",
                  path2: "",
                  img: "iconfont icon-gongcheng",
                  children: [],
                  name: "exceedance",
                  left: 60,
                },
                {
                  title: "拌合材料消耗统计",
                  path: "material",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "material",
                  left: 60,
                },
              ],
            },
            {
              title: "生产任务完成统计",
              name: "pcManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "任务单生产动态统计",
                  path: "productionAmount",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "productionAmount",
                  left: 60,
                },
                {
                  title: "任务单用料情况统计",
                  path: "materialConsumption",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  name: "materialConsumption",
                  left: 60,
                },
              ],
            },

            {
              title: "砼拌合站参数设置",
              name: "TbhxtManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "项目部拌合站信息",
                  name: "mixingPlant",
                  path: "mixingPlant",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  left: 60,
                },

                {
                  title: "材料超标参数设置",
                  name: "alarmParameterSetting",
                  path: "alarmParameterSetting",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警通知人员对象",
                  name: "warningObject",
                  path: "warningObject",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警短信模板管理",
                  name: "warningInformation",
                  path: "warningInformation",
                  path2: "",
                  img: "iconfont icon-cailiaozhengli",
                  children: [],
                  left: 60,
                },
              ],
            },
          ],
        },
        // 水稳
        {
          title: "水稳拌合生产质量管控",
          img: "iconfont icon-xitongguanli1",
          name: "WaterManage",
          left: 0,
          children: [
            {
              path: "instantly",
              path2: "",
              img: "iconfont icon-jianzhucailiao",
              children: [],
              title: "动态监控",
              name: "instantly",
              left: 37,
            },
            {
              path: "superRecord",
              path2: "",
              img: "iconfont icon-jianzhucailiao",
              children: [],
              title: "水稳超标生产拌合监控",
              name: "superRecord",
              left: 37,
            },
            {
              title: "拌合设备检定管理",
              path: "Equipment",
              path2: "EquipmentText",
              name: "Equipment",
              name2: "EquipmentText",
              img: "iconfont icon-jianzhucailiao",
              children: [],
              left: 37,
            },
            {
              title: "数据分析",
              name: "analyse",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "产能分析",
                  path: "waterProduce",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  name: "waterProduce",
                  left: 60,
                },
                {
                  title: "材料用量走势图",
                  path: "waterConsumption",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  name: "waterConsumption",
                  left: 60,
                },
                {
                  title: "材料百分比走势",
                  path: "percentage",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  name: "percentage",
                  left: 60,
                },
                {
                  title: "材料偏差走势图",
                  path: "WaterDeviation",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  name: "WaterDeviation",
                  left: 60,
                },
                {
                  title: "产量统计",
                  path: "waterOutput",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  name: "waterOutput",
                  left: 60,
                },
                {
                  title: "原材料消耗",
                  path: "waterMaterial",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  name: "waterMaterial",
                  left: 60,
                },
              ],
            },

            {
              title: "系统设置",
              name: "swHxtManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "拌合站设置",
                  name: "swMixingPlant",
                  path: "swMixingPlant",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  left: 60,
                },
                {
                  title: "材料超标参数设置",
                  name: "swAlarmParameterSetting",
                  path: "swAlarmParameterSetting",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警通知人员对象",
                  name: "sWwarningObject",
                  path: "sWwarningObject",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警短信模板",
                  path: "sWwarningInformation",
                  path2: "",
                  img: "iconfont icon-shujufenxi2",
                  children: [],
                  name: "sWwarningInformation",
                  left: 60,
                },
              ],
            },
          ],
        },
        // 沥青
        {
          // 云检沥青拌和站生产与动态监控系统
          title: "沥青拌合生产质量管控",
          img: "iconfont icon-xitongguanli1",
          name: "pitchManage",
          // path: "/real_timeMonitoring",
          path2: "",
          left: 0,
          children: [
            {
              title: "标段配方管理",
              path: "mixProportion",
              path2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              name: "mixProportion",
              left: 37,
            },
            {
              title: "拌合生产数据信息",
              path: "real_timeData",
              path2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              name: "real_timeData",
              left: 37,
            },
            {
              title: "误差监控",
              path: "errorMonitoring",
              path2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              name: "errorMonitoring",
              left: 37,
            },
            {
              title: "拌合设备检定管理",
              path: "lqEquipment",
              path2: "lqEquipmentText",
              name: "lqEquipment",
              name2: "lqEquipmentText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "数据分析",
              name: "dataAnalysisManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "误差分析",
                  path: "errorAnalysis",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  name: "errorAnalysis",
                  left: 60,
                },
                {
                  title: "生产时间段分析",
                  path: "productionPeriod",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  name: "productionPeriod",
                  left: 60,
                },
                {
                  title: "材料用量分析",
                  path: "materConsumption",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  name: "materConsumption",
                  left: 60,
                },
                {
                  title: "日统计",
                  path: "dayStatistics",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  name: "dayStatistics",
                  left: 60,
                },
                {
                  title: "生产统计",
                  path: "productionStatistics",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  name: "productionStatistics",
                  left: 60,
                },
                {
                  title: "报警数据处理",
                  path: "alarmData",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  name: "alarmData",
                  left: 60,
                },
              ],
            },

            {
              title: "系统设置",
              name: "lqxtManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "拌合站设置",
                  name: "lqMixingPlant",
                  path: "lqMixingPlant",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  left: 60,
                },
                {
                  title: "报警参数设置",
                  path: "lqAlarmParameterSetting",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  name: "lqAlarmParameterSetting",
                  left: 60,
                },
                {
                  title: "预警通知人员对象",
                  name: "lqwarningObject",
                  path: "lqwarningObject",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警短信模板",
                  path: "lqWarningInformation",
                  path2: "",
                  img: "iconfont icon-tongjibaobiao2",
                  children: [],
                  name: "lqWarningInformation",
                  left: 60,
                },
              ],
            },
          ],
        },
        // 预制梁板
        {
          title: "预制梁板信息",
          img: "iconfont icon-xitongguanli1",
          name: "bridgeManage",
          path2: "",
          left: 0,
          children: [
            {
              title: "预制梁板信息",
              path: "bridgeInformation",
              path2: "bridgeInformationText",
              name: "bridgeInformation",
              name2: "bridgeInformationText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "关键工程信息",
              path: "keyInformation",
              path2: "keyInformationText",
              name: "keyInformation",
              name2: "keyInformationText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
          ],
        },

        //张拉
        {
          title: "智能张拉质量管控",
          img: "iconfont icon-xitongguanli1",
          name: "TensionManage",
          left: 0,
          children: [
            {
              title: "张拉任务单下发",
              path: "Tension_task_list",
              path2: "Tension_task_listText",
              name: "Tension_task_list",
              name2: "Tension_task_listText",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "实时数据查询",
              path: "TensionRealTime",
              name: "TensionRealTime",
              path2: "",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "超标数据查询",
              path: "TensionExceedData",
              name: "TensionExceedData",
              path2: "",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],
              left: 37,
            },
            {
              title: "张拉质量趋势",
              path: "TensionExceedHandle",
              name: "TensionExceedHandle",
              path2: "",
              name2: "",
              img: "iconfont icon-shengchanguanli1",
              children: [],

              left: 37,
            },

            {
              title: "系统设置",

              name: "TensionYjxtManage",
              img: "iconfont icon-gongcheng",
              left: 25,
              children: [
                {
                  title: "梁场信息设置",
                  name: "TensionBeamYard",
                  path: "TensionBeamYard",
                  path2: "",
                  img: "iconfont icon-renyuanyidongyujing",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警信息设置",
                  path: "TensionEarlyWarning",
                  name: "TensionEarlyWarning",
                  path2: "",
                  img: "iconfont icon-renyuanyidongyujing",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警人员设置",
                  path: "TensionWarningPerson",
                  name: "TensionWarningPerson",
                  path2: "",
                  img: "iconfont icon-renyuanyidongyujing",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警短信模板管理",
                  name: "TensionAlertTemplate",
                  path: "TensionAlertTemplate",
                  path2: "",
                  img: "iconfont icon-renyuanyidongyujing",
                  children: [],
                  left: 60,
                },
              ],
            },
          ],
        },
        //张拉
        //压浆
        {
          title: "智能压浆质量管控",
          img: "iconfont icon-xitongguanli1",
          name: "GroutManage",
          left: 0,
          children: [
            {
              title: "压浆任务单下发",
              path: "Grout_task_list",
              path2: "Grout_task_listText",
              name: "Grout_task_list",
              name2: "Grout_task_listText",
              img: "iconfont icon-renyuanyidongyujing",
              children: [],
              left: 37,
            },
            {
              title: "实时数据查询",
              path: "GroutRealTime",
              name: "GroutRealTime",
              path2: "",
              name2: "",
              img: "iconfont icon-renyuanyidongyujing",
              children: [],
              left: 37,
            },
            {
              title: "超标数据查询",
              path: "GroutExceedData",
              name: "GroutExceedData",
              path2: "",
              name2: "",
              img: "iconfont icon-renyuanyidongyujing",
              children: [],
              left: 37,
            },
            {
              title: "压浆质量趋势",
              path: "GroutExceedHandle",
              name: "GroutExceedHandle",
              path2: "",
              name2: "",
              img: "iconfont icon-renyuanyidongyujing",
              children: [],
              left: 37,
            },

            {
              title: "系统设置",
              name: "GroutYjxtManage",
              img: "iconfont icon-gongcheng",
              left: 25,

              children: [
                {
                  title: "梁场信息设置",
                  name: "GroutBeamYard",
                  path: "GroutBeamYard",
                  path2: "",
                  img: "iconfont icon-renyuanyidongyujing",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警信息设置",
                  path: "GroutEarlyWarning",
                  name: "GroutEarlyWarning",
                  path2: "",
                  img: "iconfont icon-renyuanyidongyujing",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警人员设置",
                  path: "GroutWarningPerson",
                  name: "GroutWarningPerson",
                  path2: "",
                  img: "iconfont icon-renyuanyidongyujing",
                  children: [],
                  left: 60,
                },
                {
                  title: "预警短信模板管理",
                  name: "GroutAlertTemplate",
                  path: "GroutAlertTemplate",
                  path2: "",
                  img: "iconfont icon-renyuanyidongyujing",
                  children: [],
                  left: 60,
                },
              ],
            },
          ],
        },
        //压浆
      ],
    };
  },
  watch: {
    activePath() {
      // newValue

      this.activePath = sessionStorage.getItem("yjSmart-keyPath");
    },
  },
  mounted() {
    this.activePath =
      sessionStorage.getItem("yjSmart-keyPath") || "theoreticalMix";
    this.roleModule();
  },
  methods: {
    roleModule() {
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      var fristModule = [];
      if (ModuleList.length != 0) {
        this.treeData.map((i) => {
          //筛选大模块
          ModuleList.map((item) => {
            if (item.fEncode == i.name) {
              i.title = item.fFullname;
              fristModule.push(i);
            }
          });
        });

        fristModule.map((item) => {
          //只有两级
          item["childrens"] = [];
          item.children.map((i) => {
            ModuleList.map((j) => {
              if (i.name == j.fEncode) {
                // console.log(i, j);
                i.title = j.fFullname;
                item["childrens"].push(i);
              }
            });
          });
          item.children = item.childrens;
        });
        // 有三级
        fristModule.map((item) => {
          item.children.map((i) => {
            //二级
            i["childrens"] = [];
            i.children.map((h) => {
              //循环3级
              ModuleList.map((j) => {
                if (h.name == j.fEncode) {
                  h.title = j.fFullname;
                  i["childrens"].push(h);
                }
              });
            });

            i.children = i.childrens;
          });
        });

        fristModule.map((item) => {
          item.children.map((i) => {
            if (i.rank == 2) {
              i.path2 = "";

              ModuleList.map((j) => {
                if (i.name2 == j.fEncode) {
                  i.path2 = i.path + "Text";
                }
              });
            }
          });
        });
        this.treeData = fristModule;
      } else if (
        JSON.parse(sessionStorage.getItem("yjSmart-userInfo")).enCode ==
        "System"
      ) {
        this.getTree();
      } else {
        this.treeData = [];
        return this.$message.error("请配置对应权限");
      }
    },
    leftNameDataData(val, data) {
      // val:树接口  data:本地
      let list = [];
      if (!Array.isArray(data)) {
        return list;
      }
      list = data.map((item) => {
        if (item.children.length > 0) {
          this.leftNameDataData(val, item.children);
        }
        val.map((i) => {
          // 接口等于本地
          if (i.fEncode == item.name) {
            item.title = i.fFullname;
          }
        });

        return item;
      });

      return list;
    },
    getTree() {
      getBaseModuleList({
        fModuleid: "",
      })
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.baseModuleList;
            this.treeData = this.leftNameDataData(companyTree, this.treeData);
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },
    //侧菜单是否显示
    toggleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    openMenu(keyPath) {
      if (keyPath != "null") {
        sessionStorage.setItem("yjSmart-keyPath", keyPath);
      }
    },
    handleNodeClick(data) {
      console.log(data, 3333);
    },
  },
};
</script>
